package edu.mju.service.impl;

import edu.mju.dao.ICompanyDao;
import edu.mju.dao.impl.CompanyDaoImpl;
import edu.mju.entity.TouristCompany;
import edu.mju.entity.User;
import edu.mju.service.ICompanyService;
import edu.mju.util.EncryptUtil;
import edu.mju.util.Pager;
import edu.mju.util.StrUtil;

/**
 * @Author:wyp
 * @Date:2020/5/24 9:42
 */
public class CompanyServiceImpl implements ICompanyService {
    ICompanyDao companyDao = new CompanyDaoImpl();

    @Override
    public TouristCompany findByuserId(Integer userId) {
        TouristCompany touristCompany =companyDao.findById(userId);
        return touristCompany;
    }

    /**
     * 根据companyID 找公司
     * @param companyId
     * @return
     */
    @Override
    public TouristCompany findBycompanyId(Integer companyId) {
        TouristCompany touristCompany =companyDao.findByCompanyId(companyId);
        return touristCompany;
    }

    /**
     *  注册公司操作
     * @param company
     * @return
     */
    @Override
    public boolean save(TouristCompany company) {
        if(company == null){
            System.out.println("company为空");
            return false;
        }
        if(company.getCompanyId()==null ){
            return companyDao.insert(company);
        }else {

            return companyDao.update(company);
        }

    }

    /**
     * 删除公司操作
     * @param id 获取公司的ID
     * @return true删除成功。
     */
    @Override
    public boolean delete(Integer id) {
        boolean Isdelete = companyDao.delete(id);
        return Isdelete;
    }

    @Override
    public Pager pagernate(int page, int pageSize, TouristCompany company) {
        Pager pager = companyDao.pagenate(page,pageSize,company);
        return pager;
    }
}
